package cn.demo.app.api;

import cn.demo.app.a.domain.User;
import cn.demo.app.consts.CloudServerNamed;
import cn.demo.app.fallback.EchoFallBack;
import cn.ifloat.brick.sprofile.common.ConditionServerMode;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.util.List;

/**
 * @author: float 2022/11/2 08:54
 */
//@FeignClient(name = "cloud-example-server",fallbackFactory = EchoFallBackFactory.class) factory可以感知到触发fallback的逻辑
//@ConditionalOnMissingClass("cn.demo.app.cloud.EchoServer")


@Lazy
@ConditionServerMode
@FeignClient(name = CloudServerNamed.EXAMPLE_SERVER_NAME,contextId = "echoApi",fallback = EchoFallBack.class)
//@FeignClient(name = CloudServerNamed.EXAMPLE_SERVER_NAME)
public interface EchoApi {

    @PostMapping("echo")
    void echo(@RequestParam("msg") String msg);

    @PostMapping("user/list")
    List<User> list(@RequestBody User user);


    @GetMapping("download")
    ResponseEntity<byte[]> download() throws IOException;
}
